package com.zrf.gulimall.product.web;

import com.zrf.gulimall.product.entity.CategoryEntity;
import com.zrf.gulimall.product.service.CategoryService;
import com.zrf.gulimall.product.vo.web.Catelog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author zhanrf
 * @Date 2021/12/19 20:17
 */
@Controller
public class IndexController {
	@Resource
	private CategoryService categoryService;

	@GetMapping(value = {"/","index.html"})
	private String indexPage(Model model) {
		//1、查出所有的一级分类
		List<CategoryEntity> categoryEntities = categoryService.getLevel1Category();
		model.addAttribute("categories",categoryEntities);
		return "index";
	}


	@GetMapping(value = "/index/json/catalog.json")
	@ResponseBody
	public Map<String, List<Catelog2Vo>> getCatalogJson() {
		Map<String, List<Catelog2Vo>> catalogJson = categoryService.getCatalogJson();
		return catalogJson;
	}
}
